;;;
;;;	Author: Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;
;;;	http://www.paracadd.com
;;;	All rights reserved.
;;;
;;;	Copyright:
;;;	   Edited:
;;;
(defun c:gpdatablk ( / data_layer data_ang)
      (IF gvpno
        NIL
        (LOAD "gvpno" "\nFile GVPNO.LSP not loaded! ")
      ) ;_ end of IF
      (IF (AND (EQ (GETVAR "TILEMODE") 0); you are in Paper Space
               (SETQ cvpsset (SSGET "X" (LIST (CONS 0 "VIEWPORT")(CONS 410 (GETVAR "CTAB")))))
               (> (SSLENGTH cvpsset) 1); a floating viewport exists
          )
        (PROGN
          (IF vpset
              nil
              (LOAD "vpset" "\nFile VPSET.LSP not loaded! ")
          ) ;_ end of IF
          (IF vpset
            (PROGN
              (IF (>= (SSLENGTH cvpsset) 4)
                (PROGN
                  (IF uint NIL (LOAD "uint" "\nFile UINT.LSP not loaded! "))
                  (WHILE (NOT (AND vp#toset prev_vp#toset))
                    (SETQ vp#toset (uint 1 "2 4 6" "Enter Viewport # to place GPDGN data block in [2/4/6...] (typ. even # but 1-99 are okay" (IF prev_vp#toset prev_vp#toset 2)))
                    (IF (AND vp#toset (OR (< vp#toset 1) (> vp#toset 99)))
                      (PROGN
                        (PRINC "\n(1) vp#toset=")
                        (PRINC vp#toset)
                        (PRINC "\n")
                        (PRINC)
                        (SETQ vp#toset NIL
                              prev_vp#toset NIL
                        )
                      )
                      (PROGN
                        (SETQ prev_vp#toset vp#toset)
                        (PRINC "\n(2) prev_vp#toset=")
                        (PRINC prev_vp#toset)
                        (PRINC "\n")
                        (PRINC)
                      )
                    )
                  )
                  (SETQ vp#toset NIL)
                )
                (SETQ prev_vp#toset 2)
              )
              (IF (AND prev_vp#toset (SSGET "X" (LIST (CONS 0 "VIEWPORT")(CONS 8 (STRCAT (IF (> prev_vp#toset 9) "*VI" "*VI0") (ITOA prev_vp#toset) "*"))(CONS 410 (GETVAR "CTAB")))))
                (vpset prev_vp#toset)
                (vla-put-MSpace (vla-get-Activedocument (vlax-get-Acad-Object)) :vlax-true)
              )
            )
            (vla-put-MSpace (vla-get-Activedocument (vlax-get-Acad-Object)) :vlax-true)
          )
        )
      )
      (gvpno);get the current viewport number from the viewport layer name (custom name ??VI##?...)
             ;A viewport number is returned (stored in symbol 'viewno) only when in floating model space (inside a viewport in a layout)
             ;Model space and Paper space both return NIL
      (COND
        (viewno
          (SETQ data_layer (STRCAT
                                 "C-"
                                 (IF (> viewno 9)
                                   "VI"
                                   "VI0"
                                 )
                                 (ITOA viewno)
                                 "6DATA-NPLT"
                               )
          )
          (SETQ data_ang (*(/(- 0 (GETVAR "VIEWTWIST"))PI)180.0))
          (dodatablkins)
        )
        ((EQ (GETVAR "TILEMODE") 1)
          (SETQ data_layer (STRCAT
                                 "C-DATA6NPLT"
                               )
          )
          (SETQ data_ang 0)
          (dodatablkins)
        )
        ((EQ (GETVAR "TILEMODE") 0)
          (ALERT "You must be inside a floating viewport\nor in Model Space to insert a GPDGN Data Block")
        )
      )
)
(DEFUN dodatablkins ()
  (IF (SETQ datablkpath (FINDFILE "GPDGN_PROJECT_DATA.DWG"))
    (IF datablkpath
      (PROGN
        (IF upoint NIL (LOAD "upoint" "\nFile UPOINT.LSP not loaded! "))
        (SETQ datainspnt (upoint 1 "" "Pick block insertion point" nil nil))
        (IF make_layer_ent NIL (LOAD "make_layer_ent" "\nFile MAKE_LAYER_ENT.LSP not loaded! "))
        (make_layer_ent (LIST (CONS 8 data_layer)))
        (COMMAND "-insert" "GPDGN_PROJECT_DATA" datainspnt 1.0 data_ang)
;;;        (ENTMAKE (LIST (CONS 0 "INSERT")
;;;                       (CONS 8 data_layer)
;;;                       (CONS 10 datainspnt)
;;;                       (CONS 2 "GPDGN_PROJECT_DATA")
;;;                       (CONS 41 1.0)
;;;                       (CONS 42 1.0)
;;;                       (CONS 43 1.0)
;;;                       (CONS 50 data_ang)
;;;                       (CONS 62 256)
;;;                 ) ;_ end of LIST
;;;        ) ;_ end of ENTMAKE
        (COMMAND ".ddatte" (ENTLAST))
      )
    )
    (ALERT "GPDGN Data Block \"GPDGN_PROJECT_DATA.DWG\" was not found!")
  )
)